package com.lvyq.javaprint.factory;

import com.lvyq.javaprint.service.*;
import java.util.ServiceLoader;

/**
 * @author lvyq 打印服务工厂模式
 * @version 1.0
 * Create by 2024-08-06 15:10
 */
public class PrintServiceFactory {


    //TODO 动态服务插件化
/*   private static ServiceLoader<PrintService> loader = ServiceLoader.load(PrintService.class);
    public static PrintService getPrintService(String serviceName) {
        for (PrintService service : loader) {
            if (service.getClass().getSimpleName().equalsIgnoreCase(serviceName)) {
                return service;
            }
        }
        throw new IllegalArgumentException("Unknown print service: " + serviceName);
    }*/

    public static PrintService getPrintService(String type) {
        switch (type) {
            case "TEXT":
                return new TextPrintService();
            case "IMG":
                return new ImgPrintService();
            case "PDF":
                return new PDFPrintService();
            case "HTML":
                return new HTMLPrintService();
            default:
                throw new IllegalArgumentException("不支持的打印类型: " + type);

        }
    }



}



